package history.study.dynamic_programming;

// 70. 爬楼梯

/**
 *  1. dp[i] 为爬到第i个台阶的方案
 *  2. 递推公式：dp[i] = dp[i-1]+dp[i-2]
 *  3. dp[1] = 1, dp[2] = 2
 *  4. 从前往后进行遍历
 *  5. dp[3] = dp[1]+dp[2] = 3
 *     dp[4] = dp[3]+dp[2] = 5
 */
public class LeetCode_70 {
    public int climbStairs(int n) {
        if (n <= 0) return -1;
        if (n == 1 || n == 2) return n;
        int []state = new int[n+1];
        state[1] = 1;
        state[2] = 2;
        for (int i = 3; i <= n; i++) {
            state[i] = state[i-1] + state[i-2];
        }
        return state[n];
    }
}
